package com.thread.lesson.state;

/**
 * @Author: Mr.Xi
 * @Description: 测试线程礼让
 * @Date: Create in 15:16 2021/7/2
 * @Modified By:
 */

/**
 * 测试线程礼让：
 * 1、礼让不一定成功，看CPU心情
 */
public class TestYIeld {

    public static void main(String[] args) {
        MyYield myYield = new MyYield();
        new Thread(myYield,"a").start();
        new Thread(myYield,"b").start();
    }

}

class MyYield implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        Thread.yield();//礼让
        System.out.println(Thread.currentThread().getName()+"线程停止执行");
    }
}